Atividade 12

Questão 1

MRT_1F <- c(517.1468515630205, 85.13094142168089, 30.333207896694553, 12.694776264558937, 3.3041601673945418, 1.1823111717498882, 1.1892293502386786)
MRT_3F <- c(156.68929936163462, 11.540837783562276, 0.4512835621696538, 0.4509797929766453, 0.4502068233039181, 0.4496185276300172, 0.4543157082191288)
MRT_5F <- c(83.90319666471157, 0.3068151086494968, 0.30522314133037304, 0.3072588968084928, 0.30655265997285697, 0.3055812715727718, 0.3053297166713006)
MRT_10F <- c(29.55430642951759, 0.19832832665772515, 0.1971923924717474, 0.19796648905716516, 0.19615594370806338, 0.2034569237883263, 0.19617420889447737)
MRT_15F <- c(11.317736530583566, 0.167364215666193, 0.16172168266811013, 0.16701085329580515, 0.1598052657153692, 0.1645934043532696, 0.16216563797118075)
MRT_sem_F <- c(11.93430909937736, 0.6095414637034009, 0.6060645101029295, 0.612167181646899, 0.6146761002685637, 0.6096747087200697, 0.6125810476877268)
clock <- c(0.1, 0.5, 1, 1.5, 2, 2.5, 3)
plot(clock, MRT_1F, type = "o", col = "blue", ylim = c(min(MRT_1F, MRT_3F, MRT_5F, MRT_10F, MRT_15F, MRT_sem_F), max(MRT_1F)), ylab = "Response Time (Sec)", xlab = "Time Between Things Requests (seconds)")
lines(clock, MRT_3F, type = "o", col = "red")
lines(clock, MRT_5F, type = "o", col = "green")
lines(clock, MRT_10F, type = "o", col = "purple")
lines(clock, MRT_15F, type = "o", col = "orange")
lines(clock, MRT_sem_F, type = "o", col = "black")
legend("topright", legend = c("1 Fog", "3 Fogs", "5 Fogs", "10 Fogs", "15 Fogs", "w/o Fog"), col = c("blue", "red", "green", "purple", "orange", "black"), lty = 1, pch = 1)

barplot(matrix(c(MRT_sem_F, MRT_1F), nrow = 2, byrow = TRUE), beside = TRUE, col = c("#E6E6E6", "#666666"), log = "y", names.arg = clock, ylab = "Response Time (s)", xlab = "Time between Things requests")
legend("topright", legend = c("w/o Fog", "1 Fog"), col = c("gray", "black"), pch = c(0,15))

barplot(matrix(c(MRT_sem_F, MRT_3F), nrow = 2, byrow = TRUE), beside = TRUE, col = c("#E6E6E6", "#666666"), log = "y", names.arg = clock, ylab = "Response Time (s)", xlab = "Time between Things requests")
legend("topright", legend = c("w/o Fog", "3 Fogs"), col = c("gray", "black"), pch = c(0,15))

barplot(matrix(c(MRT_sem_F, MRT_5F), nrow = 2, byrow = TRUE), beside = TRUE, col = c("#E6E6E6", "#666666"), log = "y", names.arg = clock, ylab = "Response Time (s)", xlab = "Time between Things requests")
legend("topright", legend = c("w/o Fog", "5 Fogs"), col = c("gray", "black"), pch = c(0,15))

barplot(matrix(c(MRT_sem_F, MRT_10F), nrow = 2, byrow = TRUE), beside = TRUE, col = c("#E6E6E6", "#666666"), log = "y", names.arg = clock, ylab = "Response Time (s)", xlab = "Time between Things requests")
legend("topright", legend = c("w/o Fog", "10 Fogs"), col = c("gray", "black"), pch = c(0,15))

barplot(matrix(c(MRT_sem_F, MRT_15F), nrow = 2, byrow = TRUE), beside = TRUE, col = c("#E6E6E6", "#666666"), log = "y", names.arg = clock, ylab = "Response Time (s)", xlab = "Time between Things requests")
legend("topright", legend = c("w/o Fog", "15 Fogs"), col = c("gray", "black"), pch = c(0,15))

Questão 2

# Dados da tabela
quality_rating <- c("Good", "Very Good", "Excellent")
meal_price <- c("$10-19", "$20-29", "$30-39", "$40-49")
data <- matrix(c(53.8, 33.9, 2.6, 0.0,
                 43.6, 54.2, 60.5, 21.4,
                 2.6, 11.9, 36.8, 78.6),
               nrow = 3, byrow = TRUE)

rownames(data) <- quality_rating
colnames(data) <- meal_price
barplot(data, beside = FALSE, col = c("#1f77b4", "#ff7f0e", "#2ca02c"),
        xlab = "Meal Price", ylab = "Percentage",
        main = "Quality Rating by Meal Price",
        legend.text = rownames(data),
        args.legend = list(x = "topright", inset = c(0, -0.31)))

Questão 3

library(ggplot2)
library(dplyr)
## 
## Anexando pacote: 'dplyr'
## Os seguintes objetos são mascarados por 'package:stats':
## 
##     filter, lag
## Os seguintes objetos são mascarados por 'package:base':
## 
##     intersect, setdiff, setequal, union
data("airquality")
dados_maio <- airquality %>% filter(Month == 5)

dados_maio$Temp_C <- (dados_maio$Temp - 32) / 1.8
ggplot(dados_maio, aes(x = Temp_C)) +
  geom_histogram(aes(y = after_stat(density)), bins = 10, fill = "skyblue", color = "black", alpha = 0.7) +
  geom_density(color = "red", linewidth = 1) +
  labs(title = "Distribuicao das Temperaturas em Maio",
       x = "Temperatura (C)",
       y = "Densidade") +
  theme_minimal()

Questão 4

Error 404, a página para o dataset não foi encontrada

Questão 5

data("InsectSprays")
boxplot(count ~ spray, data = InsectSprays,
        col = "yellow",  # Preencher as caixas com a cor "yellow"
        outline = FALSE,  # Remover os outliers
        main = "Contagem de Insetos por Tipo de Inseticida",
        xlab = "Tipo de Inseticida",
        ylab = "Contagem de Insetos")

Questão 6

Questão 7

library(dplyr)
library(plotly)
## 
## Anexando pacote: 'plotly'
## O seguinte objeto é mascarado por 'package:ggplot2':
## 
##     last_plot
## O seguinte objeto é mascarado por 'package:stats':
## 
##     filter
## O seguinte objeto é mascarado por 'package:graphics':
## 
##     layout
library(RColorBrewer)
netflix_data <- read.csv("netflix_titles.csv")

single_country_data <- netflix_data %>%
  filter(!is.na(country) & trimws(country) != "" & !grepl(",", country))

country_count <- single_country_data %>%
  group_by(country) %>%
  summarise(count = n()) %>%
  arrange(desc(count))

top_10_countries <- head(country_count, 10)
fig <- plot_ly(
  data = top_10_countries, 
  labels = ~country, 
  values = ~count,    
  type = "pie",       
  textinfo = "label+percent",  
  marker = list(colors = brewer.pal(10, "Set3"))
)

fig

Questão 8

library(dplyr)
library(plotly)
netflix_data <- read.csv("netflix_titles.csv")

netflix_data_clean <- netflix_data %>%
  filter(!is.na(country) & country != "" & trimws(country) != "")

head(netflix_data_clean)
##   show_id    type title          director
## 1      s1 TV Show    3%                  
## 2      s2   Movie  7:19 Jorge Michel Grau
## 3      s3   Movie 23:59      Gilbert Chan
## 4      s4   Movie     9       Shane Acker
## 5      s5   Movie    21    Robert Luketic
## 6      s6 TV Show    46       Serdar Akar
##                                                                                                                                                                         cast
## 1 João Miguel, Bianca Comparato, Michel Gomes, Rodolfo Valente, Vaneza Oliveira, Rafael Lozano, Viviane Porto, Mel Fronckowiak, Sergio Mamberti, Zezé Motta, Celso Frateschi
## 2                                                                                   Demián Bichir, Héctor Bonilla, Oscar Serrano, Azalia Ortiz, Octavio Michel, Carmen Beato
## 3                                                               Tedd Chan, Stella Chung, Henley Hii, Lawrence Koh, Tommy Kuan, Josh Lai, Mark Lee, Susan Leong, Benjamin Lim
## 4                            Elijah Wood, John C. Reilly, Jennifer Connelly, Christopher Plummer, Crispin Glover, Martin Landau, Fred Tatasciore, Alan Oppenheimer, Tom Kane
## 5            Jim Sturgess, Kevin Spacey, Kate Bosworth, Aaron Yoo, Liza Lapira, Jacob Pitts, Laurence Fishburne, Jack McGee, Josh Gad, Sam Golzari, Helen Carey, Jack Gilpin
## 6                            Erdal Beşikçioğlu, Yasemin Allen, Melis Birkan, Saygın Soysal, Berkan Şal, Metin Belgin, Ayça Eren, Selin Uludoğan, Özay Fecht, Suna Yıldızoğlu
##         country        date_added release_year rating  duration
## 1        Brazil   August 14, 2020         2020  TV-MA 4 Seasons
## 2        Mexico December 23, 2016         2016  TV-MA    93 min
## 3     Singapore December 20, 2018         2011      R    78 min
## 4 United States November 16, 2017         2009  PG-13    80 min
## 5 United States   January 1, 2020         2008  PG-13   123 min
## 6        Turkey      July 1, 2017         2016  TV-MA  1 Season
##                                                  listed_in
## 1   International TV Shows, TV Dramas, TV Sci-Fi & Fantasy
## 2                             Dramas, International Movies
## 3                      Horror Movies, International Movies
## 4 Action & Adventure, Independent Movies, Sci-Fi & Fantasy
## 5                                                   Dramas
## 6          International TV Shows, TV Dramas, TV Mysteries
##                                                                                                                                             description
## 1              In a future where the elite inhabit an island paradise far from the crowded slums, you get one chance to join the 3% saved from squalor.
## 2  After a devastating earthquake hits Mexico City, trapped survivors from all walks of life wait to be rescued while trying desperately to stay alive.
## 3 When an army recruit is found dead, his fellow soldiers are forced to confront a terrifying secret that's haunting their jungle island training camp.
## 4     In a postapocalyptic world, rag-doll robots hide in fear from dangerous machines out to exterminate them, until a brave newcomer joins the group.
## 5       A brilliant group of students become card-counting experts with the intent of swindling millions out of Las Vegas casinos by playing blackjack.
## 6 A genetics professor experiments with a treatment for his comatose sister that blends medical and shamanic cures, but unlocks a shocking side effect.
single_country_data <- netflix_data_clean %>%
  filter(!grepl(",", country))

country_count <- single_country_data %>%
  group_by(country) %>%
  summarise(count = n()) %>%
  arrange(desc(count))

head(country_count)
## # A tibble: 6 × 2
##   country        count
##   <chr>          <int>
## 1 United States   2555
## 2 India            923
## 3 United Kingdom   397
## 4 Japan            226
## 5 South Korea      183
## 6 Canada           177
top_10_countries <- head(country_count, 10)
table <- plot_ly(
  type = "table",
  header = list(
    values = c("País", "Total de conteúdos"),
    align = c("center", "center"),
    font = list(size = 12, color = "white"),
    fill = list(color = "gray")
  ),
  cells = list(
    values = rbind(top_10_countries$country, top_10_countries$count),
    align = c("center", "center"),
    font = list(size = 12),
    fill = list(color = c("white", "lightgray"))
  )
)

table

Questão 9

library(dplyr)
library(plotly)

netflix_data <- read.csv("netflix_titles.csv")

netflix_data <- netflix_data %>%
  filter(!is.na(release_year) & !is.na(type))

netflix_data$decade <- floor(netflix_data$release_year / 10) * 10

content_by_decade <- netflix_data %>%
  group_by(decade, type) %>%
  summarise(count = n()) %>%
  arrange(decade)
## `summarise()` has grouped output by 'decade'. You can override using the
## `.groups` argument.
fig <- plot_ly(content_by_decade, 
               x = ~decade, 
               y = ~count, 
               color = ~type, 
               colors = c("blue", "yellow"), 
               type = 'scatter', 
               mode = 'lines+markers')

fig